package com.test

import com.CompressData
import com.ConvertWebp
import com.Utils
import com.boge.utils.SystemUtils
import com.utils.CompressUtils
import com.utils.WebpUtils
import kotlin.io.path.ExperimentalPathApi
import kotlin.io.path.Path
import kotlin.io.path.extension
import kotlin.io.path.walk
import kotlin.test.BeforeTest
import kotlin.test.Test

class QuautPngTest {

    @BeforeTest
    fun before() {
        System.setProperty("runPath", SystemUtils.dir)
    }

    @OptIn(ExperimentalPathApi::class)
    @Test
    fun test() {
        val list = Path("F:\\test\\image").walk().filter { it.extension == "png" }.map {
            CompressData(
                it
            )
        }.toList()
        CompressUtils.runPngQuant(list)
    }

    @OptIn(ExperimentalPathApi::class)
    @Test
    fun toWebpTest() {
        val list = Path("F:\\test\\image").walk().filter { it.extension == "png" }.map {
            ConvertWebp(
                it
            )
        }.toList()
        WebpUtils.runPngToWebp(list)
    }
    @Test
    fun testRuntime() {
        println( "--- " + Thread.currentThread().name )
        Utils.executors.execute {
            println( "--- " + Thread.currentThread().name )
            Runtime.getRuntime()
                .exec("D:\\WorkSpace\\Idea\\Kotlin\\FileWatch\\webp\\cwebp.exe -q 75 F:\\test\\image\\04.png -o F:\\test\\image\\04.png.webp")
                .waitFor()
        }

    }

    @Test
    fun testRuntime2() {

        val convertWebp = ConvertWebp(
            Path("F:\\test\\image\\wolfFang_atlas_om3t21.png"),
            100,
            false
        )
        WebpUtils.runPngToWebp(listOf(convertWebp))

    }

}